Handlebars.registerHelper('if_eq', function(v1, v2, opts) {
    if(v1 == v2)
        return opts.fn(this);
    else
        return opts.inverse(this);
});
var tpl  =  $("#myTemplate").html();
$.ajax({
    url:"/assets/script/index.hbs",
    type:"get",
    async:false,
    success:function(data){
        tpl=data;
    }
});
var template = Handlebars.compile(tpl);
$.ajax({
    url:"/index.json",
    type:"get",
    dataType:"json",
    data:{
        currentPage:1
    },
    success:function(data){
        var html = template(data);
        $('.content-check').empty();
        $('.content-check').append(html);
    },
    error: function(msg) {
        console.log(msg)
    }
})

init();
function init() {
    initEvent();
}
//初始化swiper
var mySwiper = new Swiper('.swiper-container', {
    autoplay: 2500,//可选选项，自动滑动
    pagination : '.swiper-pagination',
    paginationType : 'bullets',
    nextButton: '.swiper-button-next',
    prevButton: '.swiper-button-prev',
    loop:true,
    autoplayDisableOnInteraction : false,
    paginationClickable :true,
    noSwipingClass:'swiper-slide'
});
function initEvent(){
    $(".swiper-slide").mouseenter(function () {
        mySwiper.stopAutoplay();
    }).mouseleave(function() {
        mySwiper.startAutoplay();
    });
    $('.item-type-a').click(function(){
        $('.item-type-a').removeClass('item-active');
        $(this).addClass('item-active');
    })
    $('.to-raise').mouseenter(function(){
        $('.to-raise').removeClass('content-item-enter');
        $(this).addClass('content-item-enter');
    })
    $('.to-raise').mouseleave(function(){
        $('.to-raise').removeClass('content-item-enter');
    })
}

//分享
var clipboard = new Clipboard('.share');
clipboard.on('success', function(e) {
    alert("复制分享链接成功！您可将此网址复制给您的好友赢取奖励")
});
clipboard.on('error', function(e) {
    alert("复制失败！请手动复制")
});
$('.share').mouseenter(function(){
    $('.copy-text').css('color','#5dc167');
    $('.link-img').attr('src','/assets/img/bx-index/link-green.png');
});
$('.share').mouseleave(function(){
    $('.copy-text').css('color','#080d2d');
    $('.link-img').attr('src','/assets/img/bx-index/link-gray.png');
});